<template>
  <div class="mall-aside">
    <div class="mall-aside-block">
      <h2 @click="$router.push('/mall/all-goods')">全部商品</h2>
      <div class="list-wrapper">
        <template v-for="(spec, index) in species">
          <el-link :href="'/mall/species/' + spec.id" target="_self"><h3>{{ spec.name }}</h3></el-link>
          
          <ul>
            <li v-for="brand in brands" v-if="brand.parentId === spec.id">
              <el-link :href="'/mall/brand/' + brand.id" target="_self">
                <i class="el-icon-star-off"></i>
                <span>{{ brand.name }}</span> 
              </el-link>
            </li>
            <div class="hr" v-if="(index + 1) === spec.size"></div>
          </ul>
        </template>
      </div>
    </div>

    <div class="mall-aside-block latest-news">
      <h2>最近浏览</h2>
      <div class="list-wrapper">
        <ul>
          <li v-for="product in visited">
            <el-link :href="'/mall/product/' + product.id" target="_self">
              <el-image
                v-if="product.fromUrl"
                style="width: 20px; height: 20px;"
                :src="product.imgPath"
                fit="fill">
              </el-image>
              <el-image
                v-else
                style="width: 20px; height: 20px;"
                :src="require('@/assets/img/product/' + product.imgPath)"
                fit="fill">
              </el-image>
              <span> {{ product.name}} </span>
            </el-link>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "MallAside",
  created() {
    let _this = this
    _this.$axios.get("/product-category/species").then((res) => {
      let resData = res.data.data

      for (let idx in resData) {
        const spec = resData[idx]
        _this.species.push({
          "id": spec.id,
          "name": spec.name,
          "parentId": spec.parentId
        });
      }
    });
    _this.$axios.get("/product-category/brands").then((res) => {
      let resData = res.data.data

      for (let idx in resData) {
        const brand = resData[idx];
        _this.brands.push({
          "id": brand.id,
          "name": brand.name,
          "parentId": brand.parentId
        });
      }
    });
    _this.visited = this.$store.getters.getVisited;
  },
  data() {
    return {
      species: [],
      brands: [],
      visited: []
    }
  }
}
</script>

<style scoped>
.mall-aside {
  float: left;
  margin-left: 100px;
  width: 300px;
  text-align: left;
}

.mall-aside-block {
  background: #fff;
  box-shadow: 0 0 1px #ddd;
  margin-bottom: 20px;
}

.mall-aside-block .hr {
  margin-bottom: 20px;
}

.mall-aside-block h2 {
  background: #ccc;
  color: #fff;
  padding: 10px 15px;
  margin-bottom: 10px;
}
.mall-aside-block h2:hover {
  color: #4b96d5;
  cursor: pointer;
  text-decoration:underline
}

.mall-aside-block h3 {
  padding: 0 15px 5px 15px;
  font-weight: bold;
  color: #222;
}

.mall-aside-block ul {
  padding: 10px 15px;
}

.mall-aside-block li {
  padding: 5px;
}

.list-wrapper {
  width: 100%;
  padding-left: 30px;
}

.list-wrapper ul {
  padding-left: 20px;
}

.latest-news {
  min-height: 256px;
}

</style>